<?php $this->load->view('inc/header'); ?>
<script type="text/javascript">
$(document).ready(function()
{
	$(window).load(function ()
	{
		$("#edit_member_password").hide();
		$("#edit_profile_panel").hide();
		$("#member_edit_display").hide();
	}
	);
	$("#edit_profile_anchor").click(function ()
	{
		$("#edit_profile_panel").fadeIn(2000);
		$("#member_edit_display").fadeOut();
		$("#edit_member_password").fadeOut();
	}
	);
	$("#edit_display_anchor").click(function ()
	{
		$("#edit_member_password").fadeOut();
		$("#edit_profile_panel").fadeOut();
		$("#member_edit_display").fadeIn(2000);
	}
	);
	$("#edit_password_anchor").click(function ()
	{
		$("#edit_member_password").fadeIn(2000);
		$("#edit_profile_panel").fadeOut();
		$("#member_edit_display").fadeOut();
	}
	);
}
);
</script>
<style type="text/css">
<!--
#avatar img{
	border: medium solid #999999;
}
-->
</style>

<div class="grid_12" style="background-color:#CCCCCC;">
<!--เมนูข้าง-->
<!--เมนูข้าง-->
<div class="grid_4 alpha" style="margin-top:10px;">
<div id="side-panel-top">
<div style="padding-left: 22px; padding-top: 7px; font-weight: bold;   color:#0FB8B8; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Welcome : <span style="border:none; background: #DBDBDB; -moz-border-radius: 4px; -webkit-border-radius: 4px; padding:3px;
-moz-box-shadow: 0 1px 0 white;
-webkit-box-shadow: 0 1px 0 white;
text-decoration:none;">
<?=$this->session->userdata('username')?>
</span></div>
</div>
<div id="side-panel-middle" style="padding-left: 22px;">
<?php
$this->db->where('username',$this->session->userdata('username'));
$query = $this->db->get('membership');
foreach($query->result() as $rows)
{
	$firstname = $rows->firstname;	//firstname
	$lastname = $rows->lastname;	//lastname
	$nickname = $rows->nickname; //nickname
	$gender = $rows->gender;	//gender
	$birthdate = $rows->birthdate;	//birthdate
	$address = $rows->address;	//address;
	$province = $rows->province;
	$email = $rows->email;	//email
	$username	=	$rows->username;	//username
	$password = $rows->password;
	$member_display = $rows->member_display;	//member display
}
?>
<?php 
if($member_display == NULL)
{
	?>
	<div style="padding-left:60px;" id="avatar"><img src="<?=base_url()?>km_resource/member_display/null.png"/></div>
	<br/>
	<?php
}
else
{
?>
	<div style="padding-left:60px;"  id="avatar"><img src="<?=base_url()?>km_resource/member_display/<?=$member_display?>"/></div>
	<br/>
<?php
}
?>
<img src="<?=base_url()?>images/graphic/information-balloon.png"/>&nbsp;Profile Name:
<?=$firstname."\t".$lastname?>
<br/>
<img src="<?=base_url()?>images/graphic/book-open-next.png"/>&nbsp;Your Blog: <a href="<?=base_url()?>blog/read/<?=$nickname?>">
<?=$this->session->userdata('username')?> - blog.</a> <br/>
<br/>
<a href="<?=base_url()?>logout" style="border:none; background: #ED0C66; -moz-border-radius: 4px; -webkit-border-radius: 4px; padding:5px;
color:#FFFFFF;
box-shadow: 0 1px 0 white;
-moz-box-shadow: 0 1px 0 white;
-webkit-box-shadow: 0 1px 0 white;
text-decoration:none;">Logout</a> </div>
<div id="side-panel-bottom"></div>
<!--ปิดเมนูข้าง-->
<div class="grid_4 alpha" style="margin-top:8px;">
<div id="side-panel-top">
<div style="padding-left: 22px; padding-top: 7px; font-weight: bold;   color:#FF9933; text-shadow: 1px 1px 1px rgb(255, 255, 255);">My Blog Topics <img src="<?=base_url()?>images/graphic/rss.png"/></div>
</div>
<div id="side-panel-middle" style="padding-left: 22px;"> dfgdg </div>
<div id="side-panel-bottom"></div>
</div>
<!--เมนูข้าง-->
<div class="grid_4 alpha" style="margin-top:8px;">
<div id="side-panel-top">
<div style="padding-left: 22px; padding-top: 7px; font-weight: bold;   color:#FF9933; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Control Panel</div>
</div>
<div id="side-panel-middle" style="padding-left: 22px; cursor:pointer;">
<span id="edit_password_anchor"><img src="<?=base_url()?>images/graphic/edit_password_but.png"/></span>
<span id="edit_profile_anchor"><img src="<?=base_url()?>images/graphic/edit-profile-but.png"/></span>
<span id="edit_display_anchor"><img src="<?=base_url()?>images/graphic/upload-avatar-but.png"/></span>
</div>
<div id="side-panel-bottom"></div>
</div>
<!--ปิดเมนูข้าง-->
</div>
<!--ปิดเมนูข้าง-->
<!-- Mainpage Member -->
<div class="grid_8 omega" style="margin-top:8px;" id="main_page_member">
<div id="km-topic">
<div style="padding-left: 15px; padding-top: 11px; color: rgb(0, 0, 0); font-weight: bold; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Dashboard</div>
</div>
<div id="km-new-middle">
	<div style="padding-left:0px;">
    <?php
	/*query php*/
	$member_id = $this->session->userdata('member_id');
	
	//create blog entry
	$this->db->where('blog_author',$member_id);
	$query_b_entry = $this->db->get('blog');
	$count_b_entry = $query_b_entry->num_rows();
	
	//comment
	$this->db->where('member_id',$member_id);
	$query_b_comment = $this->db->get('blog_comment');
	$count_b_comment = $query_b_comment->num_rows();
	
	//vote blog
	$this->db->where('member_id',$member_id);
	$query_b_vote = $this->db->get('blog_vote');
	$count_b_vote = $query_b_vote->num_rows();
	
	//view log
	$this->db->where('member_id',$member_id);
	$query_b_view = $this->db->get('blog_views_log');
	$count_b_view = $query_b_view->num_rows();
	
	$summation_blog =  $count_b_entry+$count_b_comment+$count_b_vote+$count_b_view;
	
	//create cop group
	$this->db->where('owner',$member_id);
	$query_c_create = $this->db->get('cops_group');
	$count_c_create = $query_c_create->num_rows();
	
	//join group
	$this->db->where('member_id',$member_id);
	$query_c_group_in = $this->db->get('cops_group_in');
	$count_c_group_in = $query_c_group_in->num_rows();
	
	//cops files
	$this->db->where('member_id',$member_id);
	$query_c_files = $this->db->get('cops_files');
	$count_c_files = $query_c_files->num_rows();
	
	//cops discuss
	$this->db->where('member_id',$member_id);
	$query_c_discuss = $this->db->get('cops_discuss');
	$count_c_discuss = $query_c_discuss->num_rows();
	
	$summation_cops = $count_c_create+$count_c_group_in+$count_c_files+$count_c_discuss;
	
	//calculate
	$total_activity = $summation_blog+$summation_cops;
	//percences
	$blog1 = ($count_b_entry*100)/$total_activity;
	$blog2 = ($count_b_comment*100)/$total_activity;
	$blog3 = ($count_b_vote*100)/$total_activity;
	$blog4 = ($count_b_view*100)/$total_activity;
	
	$b_percent = number_format($blog1+$blog2+$blog3+$blog4,2);
	
	$cops1 = ($count_c_create*100)/$total_activity;
	$cops2 = ($count_c_group_in*100)/$total_activity;
	$cops3 = ($count_c_files*100)/$total_activity;
	$cops4 = ($count_c_discuss*100)/$total_activity;
	
	$c_percent = number_format($cops1+$cops2+$cops3+$cops4,2);

	?>
    	<script type="text/javascript">
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container'
					},
					title: {
						text: 'อัตราส่วนการใช้งานภายในระบบ แบ่งตามกิจกรรม'
					},
					plotArea: {
						shadow: null,
						borderWidth: null,
						backgroundColor: null
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
					plotOptions: {
						pie: {
							allowPointSelect: true,
							cursor: 'pointer',
							dataLabels: {
								enabled: true,
								color: '#000000',
								connectorColor: '#000000',
								formatter: function() {
									return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
								}
							},showInLegend: true

						}
					},

				    series: [{
						type: 'pie',
						name: 'Activity Charts',
						data: [
							['COPS',       <?=$c_percent?>],
							{
								name: 'Blogs',    
								y: <?=$b_percent?>,
								sliced: true,
								selected: true
							},
						]
					}]
				});
			});
				
		</script>
		<div id="container" style="width: 570px; height: 300px; margin: 0 auto"></div>
        <div id="activities_deatails">
        	<div id="topic" style="padding-left:15px;"><h3>Statistics Details</h3></div>
        	<div style="padding-left:18px; font-size:10px;">Create blog: <?=$count_b_entry?>, Comments: <?=$count_b_comment?>, Vote Count: <?=$count_b_vote?>, Views Blog: <?=$count_b_view?>, Create cops: <?=$count_c_create?>, Join Group: <?=$count_c_group_in?>, Cop Files: <?=$count_c_files?></div>
        </div>
    </div>
</div>
<div id="km-new-bottom"></div>
</div>
<!-- End Main Page Member -->
<!-- Edit Member Profiles -->
<div class="grid_8 omega" style="margin-top:10px;" id="edit_profile_panel">
<div id="km-topic">
<div style="padding-left: 15px; padding-top: 11px; color: rgb(0, 0, 0); font-weight: bold; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Edit Member Profile</div>
</div>
<div id="km-new-middle">
<div style="padding-left:15px;">
<table>
<form method="post" action="<?=base_url()?>site/edit_userprofile">
<tr>
<td>ข้อมูลส่วนตัว</td>
</tr>
<tr>
<td colspan="2"><hr/></td>
</tr>
<tr>
<td><p>ชื่อจริง</p>
<label>
<input type="text" name="firstname" id="firstname" value="<?=$firstname?>" />
</label></td>
</tr>
<tr>
<td><br />
<p>นามสกุล</p>
<label>
<input type="text" name="lastname" id="lastname" value="<?=$lastname?>" />
</label></td>
</tr>
<tr>
<td><br />
<p>ชื่อเล่น (ชื่อในบล็อก)</p>
<label>
<input type="text" name="nickname" id="nickname" value="<?=$nickname?>" />
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><br />
<p>เพศ</p>
<p>
<label>
<input type="radio" id="gender" name="gender" value="male" id="gender_0" />
ชาย</label>
<br />
<label>
<input type="radio" id="gender" name="gender" value="female" id="gender_1" />
หญิง</label>
<br />
</p>
<label></label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><br />
<p> วันเกิด</p>
<label>
<input type="text" name="birthdate" id="birthdate" value="<?=$birthdate?>" />
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><br />
<p>ที่อยู่</p>
<label>
<textarea name="address" id="address" cols="30" rows="3" ><?=$address?></textarea>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><br />
<p>จังหวัด</p>
<label>
<select name="province" id="province" style="width:203px">
<option value="1">กระบี่ </option>
<option value="2">กรุงเทพฯ </option>
<option value="3">กาญจนบุรี </option>
<option value="4">กาฬสินธุ์ </option>
<option value="5">กำแพงเพชร </option>
<option value="6">ขอนแก่น </option>
<option value="7">จันทบุรี </option>
<option value="8">ฉะเชิงเทรา </option>
<option value="9">ชลบุรี </option>
<option value="10">ชัยนาท </option>
<option value="11">ชัยภูมิ </option>
<option value="12">ชุมพร </option>
<option value="13">เชียงราย </option>
<option value="14">เชียงใหม่ </option>
<option value="15">ตรัง </option>
<option value="16">ตราด </option>
<option value="17">ตาก </option>
<option value="18">นครนายก </option>
<option value="19">นครปฐม </option>
<option value="20">นครพนม </option>
<option value="21">นครราชสีมา </option>
<option value="22">นครศรีธรรมราช </option>
<option value="23">นครสวรรค์ </option>
<option value="24">นนทบุรี </option>
<option value="25">นราธิวาส </option>
<option value="26">น่าน </option>
<option value="27">บุรีรัมย์ </option>
<option value="28">ปทุมธานี </option>
<option value="29">ประจวบคีรีขันธ์ </option>
<option value="30">ปราจีนบุรี </option>
<option value="31">ปัตตานี </option>
<option value="32">พระนครศรีอยุธยา </option>
<option value="33">พะเยา </option>
<option value="34">พังงา </option>
<option value="35">พัทลุง </option>
<option value="36">พิจิตร </option>
<option value="37">พิษณุโลก </option>
<option value="38">เพชรบุรี </option>
<option value="39">เพชรบูรณ์ </option>
<option value="40">แพร่ </option>
<option value="41">ภูเก็ต </option>
<option value="42">มหาสารคาม </option>
<option value="43">มุกดาหาร </option>
<option value="44">แม่ฮ่องสอน </option>
<option value="45">ยโสธร </option>
<option value="46">ยะลา </option>
<option value="47">ร้อยเอ็ด </option>
<option value="48">ระนอง </option>
<option value="49">ระยอง </option>
<option value="50">ราชบุรี </option>
<option value="51">ลพบุรี </option>
<option value="52">ลำปาง </option>
<option value="53">ลำพูน </option>
<option value="54">เลย </option>
<option value="55">ศรีสะเกษ </option>
<option value="56">สกลนคร </option>
<option value="57">สงขลา </option>
<option value="58">สตูล </option>
<option value="59">สมุทรปราการ </option>
<option value="60">สมุทรสงคราม </option>
<option value="61">สมุทรสาคร </option>
<option value="62">สระแก้ว </option>
<option value="63">สระบุรี </option>
<option value="64">สิงห์บุรี </option>
<option value="65">สุโขทัย </option>
<option value="66">สุพรรณบุรี </option>
<option value="67">สุราษฎร์ธานี </option>
<option value="68">สุรินทร์ </option>
<option value="69">หนองคาย </option>
<option value="70">หนองบัวลำภู </option>
<option value="71">อ่างทอง </option>
<option value="72">อำนาจเจริญ </option>
<option value="73">อุดรธานี </option>
<option value="74">อุตรดิตถ์ </option>
<option value="75">อุทัยธานี </option>
<option value="76">อุบลราชธานี </option>
</select>
</label>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><p><br />
อีเมล์</p>
<label>
<input name="email" type="text"  id="email" value="<?=$email?>" size="30" maxlength="30"/>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<br/><input type="submit" value="Edit Profile"></td>
</tr>
</form>
</table>
</div>
</div>
<div id="km-new-bottom"></div>
</div>
<script>
	$(function() {
		$( "#birthdate" ).datepicker({
			changeMonth: true,
			changeYear: true
		});
	});
</script>
<!-- Member Display -->
<div class="grid_8 omega" style="margin-top:8px;" id="member_edit_display">
<div id="km-topic">
<div style="padding-left: 15px; padding-top: 11px; color: rgb(0, 0, 0); font-weight: bold; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Upload Display</div>
</div>
<div id="km-new-middle">
	<div id="current_display" style="padding-left:15px;">
    <?php
    	if($member_display == NULL)
			{
		?>
        	<img src="<?=base_url()?>images/graphic/image-empty.png"/>
        <?php
			echo "No display picture, Please upload your display picture.";
		}
		else
			{
		?>
        	<img src="<?=base_url()?>images/graphic/image-reflection.png" style="vertical-align:middle;"/>
        <?php
			echo "Already display picture, You can edit the display picture By clicking on the Upload button.";
		}
	?>
    </div>
	<div id="form_display" style="padding-left:15px;">
    <br/>
    <form method="post" action="<?=base_url()?>site/upload_display" enctype="multipart/form-data">  
   		<input name="image1" type="file" size="70" maxlength="100" />
   		<br />  
   		<input type="submit" name="upload" value="Upload" />  
 	</form>
 </div>
</div>
<div id="km-new-bottom"></div>
</div>
<!-- End Edit Member Display -->

<!-- Member Edit Password -->
<div class="grid_8 omega" style="margin-top:8px;" id="edit_member_password">
<div id="km-topic">
<div style="padding-left: 15px; padding-top: 11px; color: rgb(0, 0, 0); font-weight: bold; text-shadow: 1px 1px 1px rgb(255, 255, 255);">Edit Password</div>
</div>
<div id="km-new-middle">
	<div id="ed_password" style="padding-left:15px;">
    	<form method="post" action="<?=base_url()?>site/edit_password">  
            <label>Current Password </label>
            <br />
            <input name="current_password" type="text" value="<?=$password?>" disabled="disabled"/>
            <br />  
            <br />
            <label>New Password </label>
            <br />
            <input name="new_password" type="password"/>
            <br />
            <br />
            <label>Confirm Password </label>
            <br />
            <input name="confirm_new_password" type="password"/>
            <br /><br />
            <input type="submit" name="edit" value="Edit Password" />  
 		</form>
    </div>
</div>
<div id="km-new-bottom"></div>
</div>
<!-- End Edit Member Password -->

</div>
<div class="clear"></div>
<!--end content1-->
<div class="grid_12" style="background-color:#CCCCCC;">&nbsp;</div>
<div class="clear"></div>
<?php $this->load->view('inc/footer'); ?>
